package model.loader;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import physics.movement.*;
import util.XMLUtils;

/**
 * @author Zach Michaelov
 */
public class MovementStrategyFactory {

    public static MovementStrategy fromNode(Node node) {
        MovementStrategy strategy = null;
        Element element = (Element) node;
        String type = XMLUtils.getTagValue("type", element);
        if (type.equals("stationary")) {
            strategy = new StationaryStrategy();
        } else if (type.equals("hero")) {
            strategy = new HeroMovementStrategy();
        } else if (type.equals("patrol")) {
            int leftBound = XMLUtils.getTagInt("leftBound", element);
            int rightBound = XMLUtils.getTagInt("rightBound", element);
            double speed = XMLUtils.getTagDouble("speed", element);
            strategy = new PatrolStrategy(leftBound, rightBound, speed);
        } else if (type.equals("wrapped")) {
            double xVelocity = XMLUtils.getTagDouble("xVelocity", element);
            double yVelocity = XMLUtils.getTagDouble("yVelocity", element);
            strategy = new WrappingMovingPlatformStrategy(yVelocity, yVelocity);

        }
        return strategy;
    }
}
